#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std; 

#define N 101

int a[2*N]; 
int n; 

int dp[2*N][2*N]; 

int main()
{
	int start, end; 
	int len; 
	int i, k, t, res; 

	//freopen("p1063.in", "r", stdin); 
	
	cin>>n; 
	
	for (i=1; i<=n; i++) {
		cin>>a[i]; 
		a[i+n]=a[i]; 
	}
	
	for (len=2; len<=n; len++) {
		for (start=1; start+len-1<2*n; start++) {
			end = start + len - 1; 
			for (k=start; k<end; k++) {
				t = dp[start][k] + dp[k+1][end] + a[start]*a[k+1]*a[end+1]; 
				dp[start][end] = max(dp[start][end], t); 
			}
		}
	}

	res = 0; 
	for (i=1; i<=n; i++) {
		res = max(res, dp[i][i+n-1]); 
	}

	cout<<res<<endl; 

	return 0; 
}


